package com.xbongbong.saas.service.impl;

import com.xbongbong.paas.enums.DelEnum;
import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.paas.toolbox.util.BeanUtil;
import com.xbongbong.pro.workorder.pojo.*;
import com.xbongbong.pro.workorder.pojo.dto.*;
import com.xbongbong.pro.workorder.pojo.vo.*;
import com.xbongbong.saas.constant.workorder.WorkOrderConstant;
import com.xbongbong.saas.domain.entity.ext.WorkOrderTemplateEntityExt;
import com.xbongbong.saas.enums.*;
import com.xbongbong.saas.model.WorkOrderTemplateModel;
import com.xbongbong.saas.service.WorkOrderSearchService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 *
 * @author 刘阳
 * @date 2019/4/8 9:55 AM
 * @since v1.0
 * @version v1.0
 */
@Service("workOrderSearchServiceImpl")
public class WorkOrderSearchServiceImpl implements WorkOrderSearchService {
    @Resource
    private WorkOrderTemplateModel workOrderTemplateModel;



    @Override
    public WorkOrderTemplateListAllVO getTemplateListAll(WorkOrderTemplateListAllDTO workOrderTemplateListAllDTO) throws IllegalAccessException, XbbException, InstantiationException {
        //初始化回参
        WorkOrderTemplateListAllVO workOrderTemplateListAllVO = new WorkOrderTemplateListAllVO();
        List<WorkOrderTemplateListPojo> templateList = new ArrayList<>();
        //入参处理
        String corpid = workOrderTemplateListAllDTO.getCorpid();
        Map<String, Object> param = new HashMap<>(4);
        param.put("corpid", corpid);
        param.put("enable", WorkOrderConstant.ENABLE);
        param.put("del", DelEnum.NORMAL.getDel());
        param.put("columns", "id,name,is_free,expected_time");
        //查询
        List<WorkOrderTemplateEntityExt> workOrderTemplateList = workOrderTemplateModel.findEntitys(param);
        //回参处理
        BeanUtil.copyPropertiesList(workOrderTemplateList, templateList, WorkOrderTemplateListPojo.class);
        workOrderTemplateListAllVO.setTemplateList(templateList);
        return workOrderTemplateListAllVO;
    }
}
